﻿// $Id: WebControlQuestion.cs 10 2008-02-29 15:58:02Z mcartoixa $
/*
 *  Copyright (C) 2007 Noury Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*! \file
 * \brief Definition of \c Salamanca.DataActivities.UI.WebControls.ControlQuestion.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

using System;
using System.Web;
using System.Web.UI.WebControls;

namespace Salamanca.DataActivities.UI.Web.WebControls
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Question implemented as a <see cref="WebControl" />.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public class WebControlQuestion:
        ControlQuestion
    {

        /// <summary>Initializes a new <see cref="WebControlQuestion" /> instance.</summary>
        public WebControlQuestion(string path, string controlId):
            base(path, controlId)
        {
        }

        /// <summary>Initializes a new <see cref="WebControlQuestion" /> instance.</summary>
        public WebControlQuestion(WebControl control):
            base(control)
        {
        }

        /// <summary>Asks the question.</summary>
        public override ActivityStateResult Ask(IActivityController controller)
        {
            AnswerController c=new AnswerController();

            IButtonControl cancel=c.GetCancelButton(Control);
            if (cancel!=null)
                cancel.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.Cancel);
                    }
                );

            IButtonControl end=c.GetEndButton(Control);
            if (end!=null)
                end.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.End);
                    }
                );

            IButtonControl next=c.GetNextButton(Control);
            if (next!=null)
                next.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.Next);
                    }
                );

            IButtonControl previous=c.GetPreviousButton(Control);
            if (previous!=null)
                previous.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.Previous);
                    }
                );

            return base.Ask(controller);
        }

    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Question implemented as a <see cref="WebControl" />.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public class WebControlQuestion<TAnswer>:
        ControlQuestion<TAnswer>
    {

        /// <summary>Initializes a new <see cref="WebControlQuestion{TAnswer}" /> instance.</summary>
        public WebControlQuestion(string path, string controlId):
            base(path, controlId)
        {
        }

        /// <summary>Initializes a new <see cref="WebControlQuestion{TAnswer}" /> instance.</summary>
        public WebControlQuestion(WebControl control):
            base(control)
        {
        }

        /// <summary>Asks the question.</summary>
        public override ActivityStateResult Ask(IActivityController controller)
        {
            AnswerController c=new AnswerController();

            IButtonControl cancel=c.GetCancelButton(Control);
            if (cancel!=null)
                cancel.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.Cancel);
                    }
                );

            IButtonControl end=c.GetEndButton(Control);
            if (end!=null)
                end.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.End);
                    }
                );

            IButtonControl next=c.GetNextButton(Control);
            if (next!=null)
                next.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.Next);
                    }
                );

            IButtonControl previous=c.GetPreviousButton(Control);
            if (previous!=null)
                previous.Click+=new EventHandler(
                    delegate {
                        controller.Execute(ActivityStateResult.Previous);
                    }
                );

            return base.Ask(controller);
        }

    }
}
